####################################################################
# Demo for using standard API functions of USB-CANmodul.
####################################################################

#============================================================
# pathes
#============================================================

INCPATH = ../Include
LIBPATH = ../library

#============================================================
# aplication settings
#============================================================

APPNAME = can_simulink
INCNAME = usbcan32.h
OBJECTS = String.o timeLib.o Socket.o can_usb.o can_simulink.o interface.o Thread.o udp_simulink.o
SOURCES = String.cpp timeLib.cpp Socket.cpp can_usb.cpp udp_simulink.cpp can_simulink.cpp interface.cpp Thread.cxx
LIBNAME = usbcan -lrt -lncurses -lmenu -lpthread


#============================================================
# compiler settings
#============================================================

MAKE = make
CC   = g++

ifeq ($(TARGET),DEBUGI)
CDEF =  -Wall -I$(INCPATH) -g --save-temps -D_DEBUGI
else
ifeq ($(TARGET),DEBUG)
CDEF =  -Wall -I$(INCPATH) -g --save-temps -D_DEBUG
else
CDEF =  -Wall -I$(INCPATH) -DNDEBUG
endif
endif


#============================================================
# entry points
#============================================================

all:
	$(MAKE) clean
	$(MAKE) app

# demo including traces but without debug infos for debugger
debug:
	@echo "# Build DEBUG-VERSION."
	$(MAKE) clean
	$(MAKE) app TARGET=DEBUG

# demo including traces and debug infos for debugger
# only available for SYSTEC
debugi:
	@echo "# Build DEBUGI-VERSION."
	$(MAKE) clean
	$(MAKE) app TARGET=DEBUGI

# demo without traces and without debug infos for debugger
release:
	@echo "# Build RELEASE-VERSION."
	$(MAKE) clean
	$(MAKE) app

app: 
	$(MAKE) depend
	$(MAKE) $(APPNAME)

clean: clean_light
	rm -f $(APPNAME)

clean_light:
	rm -f *.o
	rm -f *.i
	rm -f *.s
	rm -f *.dep

# find dependencies
depend:
	@echo "# Scan for depencies.."
	for i in $(SOURCES); do gcc -MM "$${i}" -I$(INCPATH); done > makefile.dep

#============================================================
# linking application
#============================================================

$(APPNAME): $(OBJECTS) 
	$(CC) -o $(APPNAME) $(OBJECTS) -l$(LIBNAME)

#============================================================
# compiling files
#============================================================
-include makefile.dep
	
%.o: %.c
	$(CC) $(CDEF) -c $<

%.o: %.cxx
	$(CC) $(CDEF) -c --friend-injection $<
